<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>CMS系统</title>
    <script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
    <!-- Bootstrap -->
    <link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
          rel="stylesheet">
    <!-- Font Awesome -->
    <link
            href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
            rel="stylesheet">
    <!-- NProgress -->
    <link href="<%=basePath%>vendors/nprogress/nprogress.css"
          rel="stylesheet">
    <!-- iCheck -->
    <link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
          rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link
            href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
            rel="stylesheet">
    <!-- JQVMap -->
    <link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
          rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link
            href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
            rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>
<%@ include file="loginCheck.jsp" %>
<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div class="col-md-3 left_col">
            <div class="left_col scroll-view">
                <div class="clearfix"></div>
                <br/>
            </div>
        </div>
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="row tile_count">
                        <%--<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">--%>
                            <%--<span class="count_top"><i class="fa fa-user"></i>总加油订单数</span>--%>
                            <%--<div id="counttotle" class="count">${pages.recordTotal}</div>--%>
                        <%--</div>--%>
                        <%--<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">--%>
                            <%--<span class="count_top"><i class="fa fa-clock-o"></i>总加油金额</span>--%>
                            <%--<div id="countnew" class="count">${shopf}</div>--%>
                        <%--</div>--%>
                        <%--<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">--%>
                            <%--<span class="count_top"><i class="fa fa-clock-o"></i>总收益金额</span>--%>
                            <%--<div id="usercommision" class="count">${usercommision}</div>--%>
                        <%--</div>--%>

                        <div class="title_left"></div>
                        <%--<div class="x_content">--%>
                        <%--用户手机号码：<input type="text" id="mobile" value="${mobile}"/>--%>
                        <%--所属代理商：<input type="text" id="pname" value="${username}"/>--%>
                        <%--所属商家：<input type="text" id="shopname" value="${shopname}"/>--%>
                        <%--<button type="submit" class="btn btn-default"--%>
                        <%--onclick="selectALL('1')">搜索--%>
                        <%--</button>--%>
                        <%--</div>--%>
                        <div class="clearfix"></div>
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>加油统计</h2>
                                <div class="clearfix"></div>
                                <div class="x_content">
                                    订单号： <input type="text" id="czborderid" value="${czborderid}"/>
                                    订单状态: <select id="paystatus" value="${paystatus}">
                                    <option value="0">全部</option>
                                    <option value="已支付">已支付</option>
                                    <option value="退款申请中">退款申请中</option>
                                    <option value="已退款">已退款</option>
                                    <option value="退款失败">退款失败</option>
                                </select>
                                    上级商户名称： <input type="text" id="payParentId" value="${payParentId}"/>
                                    日期范围： <input type="text" id="test10" value="${test10}">
                                    用户手机号： <input type="text" id="mobile" value="${mobile}"/>
                                    <button type="submit" class="btn btn-default"
                                            onclick="selectALL('${status}','1')">搜索
                                    </button>
                                    <c:if test="${adminUsergrade < 2 }">
                                        <button id="export" class="btn btn-default" onclick="daochu()">导出</button>
                                    </c:if>
                                </div>
                            </div>
                            <div class="x_content">
                                <table id="datatable" class="table table-striped table-bordered">
                                    <thead>
                                    <tr>
                                        <th>所属商家</th>
                                        <th>用户手机号</th>
                                        <th>订单</th>
                                        <th>油站名称</th>
                                        <th>升数</th>
                                        <th>支付金额</th>
                                        <th>订单总金额</th>
                                        <th>订单状态</th>
                                        <th>省</th>
                                        <th>市</th>
                                        <th>区</th>
                                        <th>是否扣除话费</th>
                                        <th>订单创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach items="${gasOrderList}" var="s" varStatus="z">
                                        <tr>
                                            <td>${s.parentName}</td>
                                            <td>${s.usermobile}</td>
                                            <td>${s.orderid }</td>
                                            <td>${s.gasname }</td>
                                            <td>${s.litre }L</td>
                                            <td>${s.amountpay }</td>
                                            <td>${s.amountgun }</td>
                                            <td>${s.orderstatusname }</td>
                                            <td>${s.province }</td>
                                            <td>${s.city }</td>
                                            <td>${s.county }</td>
                                            <td><c:if test="${s.ispaymoney == 0 }">
                                                未支付
                                            </c:if> <c:if test="${s.ispaymoney == 1 }">
                                                已支付
                                            </c:if></td>
                                            <td>${s.orderdt}</td>
                                            <td><c:if test="${s.ispaymoney == 0 }">
                                               <button onclick="zhifu(${s.id})">手动支付话费</button>
                                                <input type="text" id="mobile"/>
                                            </c:if> <c:if test="${s.ispaymoney == 1 }">
                                                已支付
                                            </c:if></td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                            <div style="width: 100%; text-align: center;">
                                <div id='page'></div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <br/>

                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script>
    /**
     * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
     */
    pageUtil.initPage('page', {
        totalCount: '${pages.recordTotal}', //总页数，一般从回调函数中获取。如果没有数据则默认为1页
        curPage: ${pages.currentPageNo}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
        showCount: 9, //分页栏显示的数量
        pageSizeList: [10], //自定义分页数，默认[5,10,15,20,50]
        defaultPageSize: 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
        isJump: true, //是否包含跳转功能，默认false
        isPageNum: true, //是否显示分页下拉选择，默认false
        isPN: true, //是否显示上一页和下一面，默认true
        isFL: true, //是否显示首页和末页，默认true
        jump: function (curPage) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
            selectALL(null, curPage);
        },
    });
</script>
<script type="text/javascript">
    // 主页
    function selectALL(status, curPage) {
        console.log(curPage);
        var mobile = $("#mobile").val();
        var czborderid = $("#czborderid").val();
        var paystatus = $("#paystatus").val();
        var payParentId = $("#payParentId").val();
        var dateRange= $("#test10").val();
        window.location.href = "content_gasorderH5?mobile=" + mobile + "&czborderid=" + czborderid + "&parentid=" + payParentId
            + "&currentPageNo=" + curPage + "&paystatus=" + paystatus+"&dateRange="+dateRange;
    }

    function refundSuccess(id, orderId, parentId, userId) {
        $.ajax({
            type: 'POST',
            url: 'refundSuccess',
            data: {
                id: id,
                orderId: orderId,
                parentId: parentId,
                userId, userId
            },
            success: function (date) {
                alert("审核成功");
                window.location.href = "refund";
            }
        });
    }

    function zhifu(id) {
        $.ajax({
            type: 'POST',
            url: 'gasOrderPush',
            data: {
                id: id,
                mobile:$("#mobile")
            },
            success: function (date) {
                alert("审核成功");
                window.location.href = "refund";
            }
        });
    }
</script>

<!-- jQuery -->
<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
<script src="<%=basePath%>laydate/laydate.js"></script>
<script>
    //日期时间范围
    laydate.render({
        elem: '#test10'
        ,type: 'datetime'
        ,range: true
    });

    //获取select中的选项以及value
    // ajax 对象
    function ajaxObject() {
        var xmlHttp;
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("您的浏览器不支持AJAX！");
                    return false;
                }
            }
        }
        return xmlHttp;
    }

    function daochu() {
        alert("正在导出中，请稍后……");
        var dateRange= $("#test10").val();
        if(dateRange == null || dateRange == undefined){
            alert("请根据时间段导出");
        }
        $("#export").attr("disabled", "disabled");
        var ajax = ajaxObject();
        ajax.open("post", "<%=basePath%>apiTest/gasOrderExport?dateRange=" + dateRange, true);
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        ajax.onreadystatechange = function() {
            if (ajax.readyState == 4) {
                if (ajax.status == 200) {
                    var result = JSON.parse(ajax.responseText);
                    $("#export").removeAttr("disabled");
                    if(result.headPath == "1"){
                        window.open("http://"+ result.fileName);
                    }
                    if(result.headPath == "2"){
                        window.open("https://"+ result.fileName);
                    }
                    if(result.headPath == "3"){
                        alert("域名错误！");
                    }
                } else {
                    //请求失败
                    alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
                }
            } else {
            }
        };
        ajax.send();
    }
</script>
<!-- Bootstrap -->
<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
<script
        src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- Chart.js -->
<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>

<!-- Custom Theme Scripts -->
<script src="<%=basePath%>build/js/custom.min.js"></script>
</body>
</html>